package com.dog.basics.admin.controller.common;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.dog.basics.bean.dto.admin.common.CommonProblemClassAddDto;
import com.dog.basics.bean.dto.admin.common.CommonProblemClassEditDto;
import com.dog.basics.bean.dto.admin.common.CommonProblemClassSelectDto;
import com.dog.basics.bean.vo.admin.sys.CommonProblemClassPageVo;
import com.dog.basics.common.annotation.SysLog;
import com.dog.basics.common.constant.SwaggerConstants;
import com.dog.basics.common.util.PageParam;
import com.dog.basics.common.util.R;
import com.dog.basics.service.common.ISysCommonProblemClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;

/**
 * <p>
 * 常见问题分类 前端控制器
 * </p>
 *
 * @author fengjukang
 * @since 2019-10-11
 */
@RestController
@Api(value = SwaggerConstants.COMMON+"常见问题分类", tags = SwaggerConstants.COMMON+"常见问题分类")
@RequestMapping("/admin/problem/class")
@AllArgsConstructor
@ApiIgnore
public class SysCommonProblemClassController {

    private final ISysCommonProblemClassService isyscommonproblemclassservice;

    /**
     * 常见问题分类
     *
     * @param page
     * @param dto
     * @return
     * @author guonh
     */
    @GetMapping("/page")
    @ApiOperation(value = "常见问题分类", notes = "admin:commonproblemclass:page")
    @PreAuthorize("@pms.hasPermission('admin:commonproblemclass:page')")
    public R<IPage<CommonProblemClassPageVo>> getCommonProblemClass(PageParam page, CommonProblemClassSelectDto dto) {
        return R.ok(isyscommonproblemclassservice.getCommonProblemClass(page, dto));
    }

    /**
     * 常见问题分类新增
     *
     * @param commonProblemClassAddDto
     * @return
     * @author guonh
     */
    @SysLog("常见问题分类新增")
    @ApiOperation(value = "常见问题分类新增", notes = "admin:commonproblemclass:add")
    @PostMapping("/save")
    @PreAuthorize("@pms.hasPermission('admin:commonproblemclass:add')")
    public R<Boolean> addCommonProblemClass(@Valid @RequestBody CommonProblemClassAddDto commonProblemClassAddDto) {
        return R.ok(isyscommonproblemclassservice.addCommonProblemClass(commonProblemClassAddDto));
    }

    /**
     * 常见问题分类修改
     *
     * @param commonProblemClassEditDto
     * @return
     * @author guonh
     */
    @SysLog("常见问题分类修改")
    @ApiOperation(value = "常见问题分类修改", notes = "admin:commonproblemclass:edit")
    @PutMapping("/edit")
    @PreAuthorize("@pms.hasPermission('admin:commonproblemclass:edit')")
    public R<Boolean> editCommonProblemClass(@Valid @RequestBody CommonProblemClassEditDto commonProblemClassEditDto) {
        return R.ok(isyscommonproblemclassservice.editCommonProblemClass(commonProblemClassEditDto));
    }

    /**
     * 常见问题分类删除
     *
     * @param id
     * @return
     * @author guonh
     */
    @SysLog("常见问题分类删除")
    @ApiOperation(value = "常见问题分类删除", notes = "admin:commonproblemclass:del")
    @DeleteMapping("/delete/{id}")
    @PreAuthorize("@pms.hasPermission('admin:commonproblemclass:del')")
    public R<Boolean> delCommonProblemClass(@PathVariable("id") Long id) {
        return R.ok(isyscommonproblemclassservice.delCommonProblemClass(id));
    }


}
